home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Taifun / Taifun 006 (1987-02-15)(Ossowski, Stefan)(DE)(PD).zip / Taifun 006 (1987-02-15)(Ossowski, Stefan)(DE)(PD).adf / IconExec / SetWindow.c < prev    next >
C/C++ Source or Header  |  1987-03-04  |  2KB  |  69 lines

  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  2. /* SetWindow - Set the ToolWindow for an ICON                            */
  3. /* (c) Copyright 1986 John A. Toebes, VIII   All rights reserved         */
  4. /*     120-H Northington Place,   Cary NC 27511   (919) 469-4210         */
  5. /*  This program may be used and modified for any purpose so long as     */
  6. /*  this copyright notice remains with the code and the program is not   */
  7. /*  sold and no charge is made for its use.                              */
  8. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  9.  
  10. /* To use:
  11.    1) Compile and link as any other program
  12.    2) Issue command to modify whatever Icon you wish to
  13.         SetWindow <icon> <window specifications>
  14. */
  15.  
  16. #include <stdio.h>
  17. #include <exec/types.h>
  18. #include <workbench/workbench.h>
  19. #include <workbench/icon.h>
  20. #include <workbench/startup.h>
  21.  
  22. int IconBase;
  23. extern struct WBStartup *WBenchMsg;
  24.  
  25. main(argc,argv)
  26. int argc;
  27. char *argv[];
  28. {
  29.     struct DiskObject *diskobj, *GetDiskObject();
  30.     char *savewindow;
  31.  
  32.     /* make sure we ran from CLI */
  33.     if (argc == 0) exit(1);
  34.  
  35.     /* make sure we have enough parms */
  36.     if (argc != 2 && argc != 3)
  37.         {
  38.         printf("Usage: %s <icon> [<windowspec>]\n", argv[0]);
  39.         exit(2);
  40.         }
  41.  
  42.     if ( (IconBase = OpenLibrary( ICONNAME, 1)) == NULL)
  43.         exit(2);
  44.  
  45.     /* get the icon from disk */
  46.     if ( (diskobj = GetDiskObject(argv[1])) == NULL)
  47.         {
  48.         printf("Cannot read icon for %s\n", argv[1]);
  49.         CloseLibrary( IconBase );
  50.         exit(3);
  51.         }
  52.  
  53.     /* remember what the previous window was */
  54.     savewindow = diskobj->do_ToolWindow;
  55.  
  56.     /* set it to what was requested */
  57.     diskobj->do_ToolWindow = (argc > 2) ? argv[2] : NULL;
  58.  
  59.     /* write the corrected ICON to disk */
  60.     if (!PutDiskObject( argv[1], diskobj))
  61.         printf("Cannot write new icon - code %d\n", IoErr() );
  62.  
  63.     /* restore the oldwindow and free the object */
  64.     diskobj->do_ToolWindow = savewindow;
  65.     FreeDiskObject( diskobj );
  66.  
  67.     CloseLibrary( IconBase );
  68. }
  69.